﻿namespace LS.Nc6.Application.System
{
    /// <summary>
    /// 提供系统配置服务
    /// </summary>

    public class SysConfigurationService : BaseService<SysConfigurationEntity>, ISysConfigurationService, ITransient
    {
        #region 实现接口方法

        /// <summary>
        /// 根据编码获得配置信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async  Task<SysConfigurationEntity> GetByCode(string code)
        {
            return await DbContext.Instance.Queryable<SysConfigurationEntity>().FirstAsync(w => w.Code == code);
        }
        /// <summary>
        /// 根据编码获得配置信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<string> GetValueByCode(string code)
        {
            var config = await GetByCode(code);
            if (config != null)
            {
                return config.Args;
            }
            return "";
        }
      
        #endregion 实现接口方法

        /// <summary>
        /// 查询编码是否重复
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bm"></param>
        /// <returns></returns>
        public async  Task<bool> ExistsBm(string id, string bm)
        {
         return  await DbContext.Instance.Queryable<SysConfigurationEntity>().WhereIF(!string.IsNullOrEmpty(id),it=>it.Id != id.ParseToLong())
                .WhereIF(!string.IsNullOrEmpty(bm),it=>it.Code == bm ).CountAsync()>0;
        }

        
        public async  Task<string> GetBillNumber(string billName, string prefixes, int isContinuous = 0, int billLen = 6)
        {
            //var p = new DynamicParameters();
            //p.Add("BillName", billName);
            //p.Add("Prefixes", prefixes);
            //p.Add("IsContinuous", isContinuous);
            //p.Add("BillLen", billLen);
            //p.Add("OutPutBillNo","", dbType: DbType.String, direction: ParameterDirection.Output,200);
            //SqlHelper.Execute("p_getbillNo", p, commandType: CommandType.StoredProcedure);
            //return p.Get<string>("OutPutBillNo");

            return await Task.FromResult(string.Empty);

        }
    }
}
